-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Iterator::advance_by contract inconsistency #89916
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
de31b95
to
17ce56f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I also noticed in #91000 that the "k always less than n" was inconsistent with the 0 special case. Thanks for fixing this.
@bors r+ |
📌 Commit 17ce56f has been approved by |
…tolnay Fix Iterator::advance_by contract inconsistency The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n. It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator. These statements are inconsistent. Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too. While adding some tests I also found a bug in `Take::advance_back_by`.
@bors r- Failed in rollup: #91024 (comment) Looks like this fails when run with overflow-checks enabled. |
The reason CI checks are green here is because overflow checks were added after this PR was submitted (in #89776). |
17ce56f
to
04cecdf
Compare
The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n. It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator. These statements are inconsistent. Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too. While adding some tests I also found a bug in `Take::advance_back_by`.
04cecdf
to
3f9b26d
Compare
@bors r+ |
📌 Commit 3f9b26d has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (5fd3a5c): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Thanks for all the reviews @dtolnay |
The
advance_by(n)
docs state that in the error caseErr(k)
that k is always less than n.It also states that
advance_by(0)
may returnErr(0)
to indicate an exhausted iterator.These statements are inconsistent.
Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too.
While adding some tests I also found a bug in
Take::advance_back_by
.